﻿using IdentityServer4.EntityFramework.DbContexts;
using IdentityServer4.EntityFramework.Entities;
using IdentityServer4.EntityFramework.Options;

namespace Ids4.Api.Data.Mysql
{
    public class MysqlPersistedGrantDbContext : PersistedGrantDbContext<MysqlPersistedGrantDbContext>
    {
        public MysqlPersistedGrantDbContext(DbContextOptions<MysqlPersistedGrantDbContext> options, OperationalStoreOptions storeOptions) : base(options, storeOptions)
        {

        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.EnableSensitiveDataLogging();
            optionsBuilder.UseSnakeCaseNamingConvention();
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<DeviceFlowCodes>().ToTable("device_flowcode").Property(d => d.Data).HasColumnType("text");
            modelBuilder.Entity<PersistedGrant>().ToTable("persisted_grant").Property(d => d.Data).HasColumnType("text");
        }
    }
}
